<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{{ title }} - 股票新闻分析系统</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">
    <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
</head>

<body>
    <nav class="navbar navbar-expand-lg navbar-dark bg-primary">
        <div class="container">
            <a class="navbar-brand" href="/">股票新闻分析系统</a>
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarNav">
                <ul class="navbar-nav">
                    <li class="nav-item">
                        <a class="nav-link active" href="/">首页</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="/dashboard">仪表盘</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="/reports">策略报告</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="/llm_analysis">大模型分析</a>
                    </li>
                </ul>
            </div>
        </div>
    </nav>

    <div class="container mt-4">
        <div class="jumbotron bg-light p-5 rounded">
            <h1 class="display-4">欢迎使用股票新闻分析系统</h1>
            <p class="lead">基于新闻分析预测股票趋势，为您提供每日投资策略</p>
            <hr class="my-4">
            <p>本系统通过实时收集财经新闻，结合自然语言处理、大语言模型和机器学习技术，分析新闻对股票市场的影响，预测股票价格走势，生成可靠的投资建议。</p>
            <a class="btn btn-primary btn-lg" href="/dashboard" role="button">查看仪表盘</a>
            <a class="btn btn-success btn-lg ms-2" href="/reports" role="button">查看最新报告</a>
            <a class="btn btn-info btn-lg ms-2" href="/llm_analysis" role="button">大模型分析</a>
        </div>

        <div class="row mt-4">
            <div class="col-md-6">
                <div class="card">
                    <div class="card-header bg-primary text-white">
                        <h5 class="card-title mb-0">今日市场概览</h5>
                    </div>
                    <div class="card-body" id="market-overview">
                        <p class="text-center">加载中...</p>
                    </div>
                </div>
            </div>
            <div class="col-md-6">
                <div class="card">
                    <div class="card-header bg-success text-white">
                        <h5 class="card-title mb-0">热门推荐</h5>
                    </div>
                    <div class="card-body" id="hot-recommendations">
                        <p class="text-center">加载中...</p>
                    </div>
                </div>
            </div>
        </div>

        <div class="row mt-4">
            <div class="col-md-12">
                <div class="card">
                    <div class="card-header bg-info text-white">
                        <h5 class="card-title mb-0">今日热点新闻</h5>
                    </div>
                    <div class="card-body" id="hot-news">
                        <p class="text-center">加载中...</p>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <footer class="bg-dark text-white text-center py-3 mt-5">
        <div class="container">
            <p class="mb-0">股票新闻分析系统 &copy; 2025 版权所有</p>
        </div>
    </footer>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
    <script>
        // 加载市场概览
        fetch('/api/reports?days=1')
            .then(response => response.json())
            .then(data => {
                const marketOverviewEl = document.getElementById('market-overview');
                if (data.length > 0) {
                    marketOverviewEl.innerHTML = `
                        <h6>日期: ${data[0].date}</h6>
                        <p>${data[0].market_overview}</p>
                        <div class="d-flex justify-content-between">
                            <span class="badge bg-primary">推荐: ${data[0].recommendation_count}支股票</span>
                            <span class="badge bg-warning">风险等级: ${data[0].risk_level}</span>
                        </div>
                    `;
                } else {
                    marketOverviewEl.innerHTML = '<p class="text-center">暂无今日市场概览</p>';
                }
            });

        // 加载热门推荐
        fetch('/api/stocks')
            .then(response => response.json())
            .then(data => {
                const hotRecommendationsEl = document.getElementById('hot-recommendations');
                if (data.length > 0) {
                    const topStocks = data
                        .filter(stock => stock.prediction === '上涨')
                        .sort((a, b) => b.confidence - a.confidence)
                        .slice(0, 5);

                    if (topStocks.length > 0) {
                        hotRecommendationsEl.innerHTML = `
                            <div class="list-group">
                                ${topStocks.map(stock => `
                                    <a href="/stock/${stock.code}" class="list-group-item list-group-item-action">
                                        <div class="d-flex w-100 justify-content-between">
                                            <h6 class="mb-1">${stock.name} (${stock.code})</h6>
                                            <small class="text-success">置信度: ${(stock.confidence * 100).toFixed(1)}%</small>
                                        </div>
                                        <p class="mb-1">行业: ${stock.industry}</p>
                                    </a>
                                `).join('')}
                            </div>
                        `;
                    } else {
                        hotRecommendationsEl.innerHTML = '<p class="text-center">暂无推荐股票</p>';
                    }
                } else {
                    hotRecommendationsEl.innerHTML = '<p class="text-center">暂无股票数据</p>';
                }
            });

        // 加载热点新闻
        fetch('/api/news?days=1')
            .then(response => response.json())
            .then(data => {
                const hotNewsEl = document.getElementById('hot-news');
                if (data.length > 0) {
                    hotNewsEl.innerHTML = `
                        <div class="list-group">
                            ${data.slice(0, 5).map(news => `
                                <a href="${news.url}" target="_blank" class="list-group-item list-group-item-action">
                                    <div class="d-flex w-100 justify-content-between">
                                        <h6 class="mb-1">${news.title}</h6>
                                        <small>${news.date}</small>
                                    </div>
                                    <p class="mb-1">${news.content}</p>
                                    <small>来源: ${news.source} | 相关股票: ${news.related_stocks.join(', ')}</small>
                                </a>
                            `).join('')}
                        </div>
                    `;
                } else {
                    hotNewsEl.innerHTML = '<p class="text-center">暂无今日热点新闻</p>';
                }
            });
    </script>
</body>

</html>